<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\common\library\Token;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function _initialize()
    {
        parent::_initialize();
        $cate=db('Category')->where('status','normal')
            ->where('type','default')
            ->order('weigh asc')
            ->where('pid',0)->select();
        foreach ($cate as &$v){
            $check_child=db('Category')->where('status','normal')->where('type','default')
                ->where('pid',$v['id'])
                ->order('weigh asc')
                ->select();
            if ($check_child){
                $v['child']=$check_child;
            }
            $v['data']=db('work')->where('cid',$v['id'])->limit(20)->order('id desc')->select();
        }
        $theme=db('WorkTheme')->where('status',1)->select();
        $this->assign('theme',$theme);
        $this->assign('cate',$cate);
        $this->assign('cid',input('cid'));
        $userinfo=$this->auth->getUserinfo();
        if (empty($userinfo)){
            $userinfo=['username'=>'','id'=>0,'avatar'=>''];
        }
//        dump($userinfo);exit();
        $this->assign('userinfo',$userinfo);
    }

    public function _empty()
    {
        $this->index();
    }

    public function index()
    {
//        dump(session('userinfo'));exit();
        return view();
    }

    public function news()
    {
        $newslist = [];
        return jsonp(['newslist' => $newslist, 'new' => count($newslist), 'url' => 'https://www.fastadmin.net?ref=news']);
    }

}
